// Test script for registration API
const axios = require('axios');

const API_URL = 'http://localhost:3000/api';

// Valid registration data
const userData = {
  username: 'testuser' + Math.floor(Math.random() * 1000),  // Random username to avoid conflicts
  email: `testuser${Math.floor(Math.random() * 1000)}@example.com`,  // Random email
  password: 'password123',
  full_name: 'Test User',
  phone: '1234567890',
  address: 'Test Address, City'
};

console.log('Testing registration with data:', userData);

async function testRegistration() {
  try {
    console.log(`Making POST request to ${API_URL}/auth/register`);
    const response = await axios.post(`${API_URL}/auth/register`, userData);
    
    console.log('Registration successful!');
    console.log('Response:', response.data);
    return true;
  } catch (error) {
    console.error('Registration failed!');
    
    if (error.response) {
      // The request was made and the server responded with a status code
      // that falls out of the range of 2xx
      console.error('Status:', error.response.status);
      console.error('Data:', error.response.data);
      console.error('Headers:', error.response.headers);
    } else if (error.request) {
      // The request was made but no response was received
      console.error('No response received from server');
      console.error(error.request);
    } else {
      // Something happened in setting up the request that triggered an Error
      console.error('Error:', error.message);
    }
    
    return false;
  }
}

testRegistration(); 